<!DOCTYPE html>
<html lang="en">

<!--#include file="common/header.html"-->
<body>
    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <!--头部搜索-->
                <section class="panel panel-padding">
                    <form class="layui-form" action="/education/admin/address">
                        <input type="hidden" name="_query.userid">
                        <div class="layui-form">
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="_query.keyword" placeholder="关键字">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button lay-submit class="layui-btn" lay-filter="search">查找</button>
                            </div>
                        </div>
                    </form>
                </section>

                <!--列表-->
                <section class="panel panel-padding">
                    <div class="group-button">
                        <!--<button class="layui-btn layui-btn-small modal-catch" beforeFun="beforeAdd"
                                data-params='{"content":".add-subcat", "title":"添加","type":"1",  "maxmin":"true"}'>
                            <i class="iconfont">&#xe649;</i> 添加
                        </button>-->
                        <button class="layui-btn layui-btn-small layui-btn-danger ajax-all" data-name="checkbox" data-params='{"url": "/education/admin/address/delete"}'>
                            <i class="iconfont">&#xe626;</i> 删除
                        </button>
                    </div>
                    <div id="list" class="layui-form"></div>

                    <div class="text-right" id="page"></div>
                </section>
            </div>
        </div>
    </div>
    <div class="add-subcat">
        <form class="layui-form layui-form-pane" action="/education/admin/address/update" id="form1">
            <input type="hidden" name="a.id">

            <div class="layui-form-item">
                <label class="layui-form-label">收货人</label>
                <div class="layui-input-block">
                    <input type="text" name="a.receiver" required jq-verify="required" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-block">
                    <input type="text" name="a.tel" required jq-verify="required" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">客户地址</label>
                <div class="layui-input-inline">
                    <select name="a.province_id" id="pId" lay-filter="p1" style="width: 120px;" required jq-verify="required">
                        <option value="">请选择省</option>
                    </select>
                </div>
                <div class="layui-input-inline" id="cityId" style="width: 120px;">
                    <select name="a.city_id" lay-filter="city" required jq-verify="required">
                        <option value="">请选择市</option>
                    </select>
                </div>
                <div class="layui-input-inline"  id="districtId" style="width: 120px;">
                    <select name="a.district_id" lay-filter="district" required jq-verify="required">
                        <option value="">请选择县/区</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">详细地址</label>
                <div class="layui-input-block">
                    <input type="text" name="a.detail" required jq-verify="required"  class="layui-input ">
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" jq-submit jq-filter="submit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>


</body>
<!--#include file="address-list.html"-->
<script src="../js/layui/layui.js"></script>
<script type="text/javascript" src="../js/lib/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../js/lib/rest.js"></script>
<script type="text/javascript" src="js/area_select.js"></script>

<!--#include file="common/version.html"-->
<script>
    layui.use('user_list');

    function initData() {
        var uid = getQueryString('uid') || '';
        var json = JSON.parse($("#list-tpl").attr('data-params'));
        json['url'] = json['url'] + '?_query.userid=' + uid;
        $("#list-tpl").attr('data-params', JSON.stringify(json));
        $('input[name="_query.userid"]').val(uid);
    }

    function beforeAdd(obj){
        $('#form1').attr('action', '/education/admin/address/save');
    }

    function viewDetail(ids){
        var index = layer.open({
            type: 1,
            title:'编辑',
            content: $('.add-subcat'),
            area:['650px']
        });
        //$('#form1').attr('action', '/education/admin/address/update/' + ids);
        restGet('/education/admin/address/view/' + ids, null, $('#form1'), function(rs){
            initSelectData(rs.data.province_id, rs.data.city_id);
            initSelectData2(rs.data.city_id, rs.data.district_id);
        })
    }

    function initSelectData(val, cityId){
        var url = "/education/api/area?parentId=";
        $.post(url+val+'&level=2', function(rs){
            var str = "<option value=''></option>";
            $.each(rs.data, function(i,item){
                str += '<option value="' + item.id + '">'+ item.name +'</option>';
            });
            $("select[name='a.city_id']").html(str);
            $("select[name='a.city_id']").val(cityId);
            var form = layui.form();
            // $('#cityId').find('dl').find('dd[lay-value="' + cityId + '"]').click();// 查找点击
            form.render();
        });
    }
    function initSelectData2(val, districtId){
        var url = "/education/api/area?parentId=";
        $.post(url+val+'&level=3', function(rs){
            var str = "<option value=''></option>";
            $.each(rs.data, function(i,item){
                str += '<option value="' + item.id + '">'+ item.name +'</option>';
            });
            $("select[name='a.district_id']").html(str);
            var form = layui.form();
            form.render('select')
            $('#districtId').find('dd[lay-value="' + districtId + '"]').click();
            form.render();
        });
    }
</script>

</html>